/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.aeso.betabit.util;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Edson
 */
public class RMI {

    private static Registry registry;
    
    private static final int RMI_PORT = 8081;

    public static void register(Remote service) throws RemoteException {
        if (service instanceof UnicastRemoteObject) {
            registry.rebind(service.getClass().getSimpleName(), service);
        }
    }

    public static void startup(Remote... services) {
        try {
            registry = LocateRegistry.createRegistry(RMI_PORT);
            for (Remote service : services) {
                RMI.register(service);
            }
        } catch (RemoteException ex) {
            Logger.getLogger(RMI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}